package com.yuerlive.rainbow.module.playlive.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.entity.GameInfo;
import com.yuerlive.rainbow.utils.GlideUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by xiaoyi on 2017/6/13.
 */

public class GameListAdapter extends BaseAdapter {
    private List<GameInfo> mDatas;
    private Context context;
    private boolean start;

    public GameListAdapter(List<GameInfo> mDatas, Context context) {
        this.mDatas = mDatas;
        this.context = context;
    }

    public GameListAdapter(List<GameInfo> mDatas, Context context,boolean start) {
        this.mDatas = mDatas;
        this.context = context;
        this.start = start;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_live_gamelist, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        GameInfo game = mDatas.get(position);
       if (game.isSelected()){
           holder.tvState.setVisibility(View.VISIBLE);
       }else {
           holder.tvState.setVisibility(View.GONE);
       }
       if (start){
           holder.tvState.setText("已选择");
       }else {
           holder.tvState.setText("关闭游戏");
       }

       if (position!=mDatas.size()-1){
           GlideUtil.load(context,game.getCoverIcon(),holder.ivIcon);
       }else {
           holder.ivIcon.setImageResource(R.drawable.ic_gamemore);
       }
        holder.tvName.setText(game.getName());


        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.ivIcon)
        ImageView ivIcon;
        @BindView(R.id.tvState)
        TextView tvState;
        @BindView(R.id.tvName)
        TextView tvName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
